package com.beyondsoft.common.activiti.support;

import com.beyondsoft.common.activiti.exception.ActivitiException;
import com.beyondsoft.common.activiti.exception.ResultCode;
import com.beyondsoft.common.activiti.mapper.WorkflowExtMapper;
import com.beyondsoft.common.activiti.model.TaskData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhangyan
 * @version $ Id: QueryToDoTaskSupport.java, v 0.1 2020/6/22 19:49 zhangyan Exp $
 */
@Component
public class QueryToDoTaskSupport {

    @Resource
    private WorkflowExtMapper workflowExtMapper;

    /**
     * 查询待办
     *
     * @param assignee 用户
     * @return 任务列表
     */
    public List<TaskData> queryToDoTasks(String assignee) {
        if (StringUtils.isBlank(assignee)) {
            throw new ActivitiException(ResultCode.NO_DATA.getCode(), "参数为空");
        }
        return workflowExtMapper.queryToDoTasks(assignee);
    }

    /**
     * 查询已办
     *
     * @param assignee 用户
     * @return 任务列表
     */
    public List<TaskData> queryDoneTasks(String assignee) {
        if (StringUtils.isBlank(assignee)) {
            throw new ActivitiException(ResultCode.NO_DATA.getCode(), "参数为空");
        }
        return workflowExtMapper.queryDoneTasks(assignee);
    }

    /**
     * 查询我发起的任务
     *
     * @param assignee 用户
     * @return 任务列表
     */
    public List<TaskData> queryUserLaunchTask(String assignee) {
        if (StringUtils.isBlank(assignee)) {
            throw new ActivitiException(ResultCode.NO_DATA.getCode(), "参数为空");
        }
        return workflowExtMapper.queryUserLaunchTask(assignee);
    }
}
